﻿using System.Data;
using System.Diagnostics;
using System.Web.Configuration;
using System.Web;
using System.Configuration;
using System;
using XunPan.Web.Contents;
using System.Net.Configuration;


namespace SalePartial.Utility
{


    //*********************************************************************
    //
    // 类：社区全局类
    // This class contains common utility methods used throughout 
    // the website Framework such as path manipulation and text
    // formatting methods.
    // 描述：该类包含一般的实用方法，这些方法在website框架中普遍地使用
    // 比如路径处理和文本格式化方法等等
    //*********************************************************************
    public class GlobalSetting
    {

        public static int SiteID
        {
            get
            {
                try
                {
                    return ((SiteInfo)HttpContext.Current.Items["SiteInfo"]).ID;
                }
                catch
                {
                    return 0;
                }
            }
        }


        //*********************************************************************
        //
        // CommunityName Property
        // 属性：社区名称
        // Represents the name of the current community. This property
        // is valid after the CommunitiesModule handles the 
        // BeginRequest event. 
        // 描述：表示目前社区的名称
        // 这个属性在系统模块类对beginrequest事件处理之后才有效
        //*********************************************************************

        public static string SiteName
        {
            get { return ((SiteInfo)HttpContext.Current.Items["SiteInfo"]).Name; }
        }

        //*********************************************************************
        // 该类是基类
        // CommunityID Property
        // 属性：社区id
        // Represents the ID of the current community. This property
        // is valid after the CommunitiesModule handles the 
        // BeginRequest event. 
        // 描述：表示目前社区的id
        // 这个属性在系统模块类对beginrequest事件处理之后才有效
        //*********************************************************************

        public static Guid SiteUniqueID
        {
            get
            {
                try
                {
                    return ((SiteInfo)HttpContext.Current.Items["SiteInfo"]).UniqueID;
                }
                catch
                {
                    return Guid.Empty;
                }
            }
        }

        //判断是否为数字
        public int IsNumeric(string str)
        {
            int i = 0;
            if (str != null && System.Text.RegularExpressions.Regex.IsMatch(str, "^\\d+$"))
            {
                i = int.Parse(str);
            }
            else
            {
                i = -1;
            }
            return i;
        }

        public static int WareCubeTotalCount
        {
            get
            {
                object count = HttpContext.Current.Application["wareCube_TotalCount"];

                if (count != null)
                {
                    return Convert.ToInt32(count);
                }
                else
                {
                    return 0;
                }
            }
            set
            {
                if (HttpContext.Current.Application["wareCube_TotalCount"] != null)
                {
                    HttpContext.Current.Application.Remove("wareCube_TotalCount");
                }

                HttpContext.Current.Application["wareCube_TotalCount"] = value;
            }
        }



        // *********************************************************************
        //  Configuration Settings Methods配置设定的一些方法
        // *********************************************************************



        //*********************************************************************
        //
        // ConnectionString Property
        // 属性：数据库连接字符串
        // Retrieves database connection string from
        // Web.Config file.
        // 描述：从web.config文件获得数据库连接字符串
        //*********************************************************************

        public static string ConnectionString
        {
            get { return ConfigurationManager.ConnectionStrings["XunPanConnectionString"].ToString(); }
        }

        //*********************************************************************
        //
        // DomainName Property
        // 属性：数据库连接字符串
        // Retrieves database connection string from
        // Web.Config file.
        // 描述：从web.config文件获得数据库连接字符串
        //*********************************************************************

        public static string AppName
        {

            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/domains"), NameValueCollection)
            //Return nvc("domainName")

            get { return ConfigurationManager.AppSettings["appName"].ToString(); }
        }


        //*********************************************************************
        //
        // DomainName Property
        // 属性：数据库连接字符串
        // Retrieves database connection string from
        // Web.Config file.
        // 描述：从web.config文件获得数据库连接字符串
        //*********************************************************************

        public static string DomainName
        {

            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/domains"), NameValueCollection)
            //Return nvc("domainName")

            get { return ConfigurationManager.AppSettings["domainName"].ToString(); }
        }

        //*********************************************************************
        //
        // IspUsername Property
        // 属性：ISP管理员账户名称
        // Retrieves the ISP Admin Username from the
        // Web.Config file.
        // 描述：从web.config文件获得ISP管理员账户名称
        //*********************************************************************

        public static string IspUsername
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/Isp"), NameValueCollection)
            //Return nvc("IspUsername")
            get { return ConfigurationManager.AppSettings["IspUsername"].ToString(); }
        }



        //*********************************************************************
        //
        // IspPassword Property
        // 属性：ISP管理员账户密码
        // Retrieves the ISP Admin Password from the
        // Web.Config file.
        // 描述：从web.config文件获得ISP管理员账户密码
        //*********************************************************************

        public static string IspPassword
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/Isp"), NameValueCollection)
            //Return nvc("IspPassword")
            get { return ConfigurationManager.AppSettings["IspPassword"].ToString(); }
        }



        //'*********************************************************************
        //'
        //' EnableServiceTimer Property
        //' 属性：启动服务计数器
        //' Retrieves the enableServiceTimer setting from the Web.Config file.
        //' 描述：从web.config文件获得启动服务计数器的相关设置
        //'*********************************************************************

        //Public Shared ReadOnly Property EnableServiceTimer() As Boolean
        //    Get
        //        Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/services"), NameValueCollection)
        //        Return Boolean.Parse(nvc("enableServiceTimer"))
        //    End Get
        //End Property



        //*********************************************************************
        //
        // UrlBasePage Property
        // 属性：UrlBasePage
        // Retrieves the path of the SITE default page from the
        // Web.Config file.
        // 描述：从web.config文件获得UrlBasePage
        //*********************************************************************

        public static string UrlBasePage
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/pagePaths"), NameValueCollection)
            //Return AppPath + nvc("basePage")
            get { return ConfigurationManager.AppSettings["basePage"].ToString(); }
        }

        //*********************************************************************
        //
        // UrlHomePage Property
        // 属性：UrlBasePage
        // Retrieves the path of the SITE page from the
        // Web.Config file.
        // 描述：从web.config文件获得homePagem,指示网站首页路径
        //*********************************************************************

        public static string UrlHomePage
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/pagePaths"), NameValueCollection)
            //Return AppPath + nvc("basePage")
            get { return ConfigurationManager.AppSettings["homePage"].ToString(); }
        }

        //*********************************************************************
        //
        // UrlHomePage Property
        // 属性：UrlBasePage
        // Retrieves the path of the community default page from the
        // Web.Config file.
        // 描述：从web.config文件获得homePagem,指示网站首页路径
        //*********************************************************************

        public static string InventorFileFolder
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/pagePaths"), NameValueCollection)
            //Return AppPath + nvc("basePage")
            get { return ConfigurationManager.AppSettings["InventorFileFolder"].ToString(); }
        }
        public static string InventorFileFolderServerPath
        {
            get { return HttpContext.Current.Server.MapPath(InventorFileFolder) + "\\"; }
        }



        public static bool EnableAltURL
        {
            get
            {
                //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/pagePaths"), NameValueCollection)
                //Return AppPath + nvc("basePage")
                string s = ConfigurationManager.AppSettings["enableAltURL"].ToString();
                if (s == "True")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }



        public static string SavedFileFolder
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/pagePaths"), NameValueCollection)
            //Return AppPath + nvc("basePage")
            get { return ConfigurationManager.AppSettings["savedFileFolder"].ToString(); }
        }

        public static string SavedFileFolderServerPath
        {
            get { return HttpContext.Current.Server.MapPath(SavedFileFolder) + "\\"; }
        }

        public static string SavedFileFolderVirtualPath
        {
            get { return SavedFileFolder + "/"; }
        }


        public static string TradeFileFolder
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/pagePaths"), NameValueCollection)
            //Return AppPath + nvc("basePage")
            get { return ConfigurationManager.AppSettings["tradeFileFolder"].ToString(); }
        }

        public static string TradeFileFolderServerPath
        {
            get { return HttpContext.Current.Server.MapPath(TradeFileFolder) + "\\"; }
        }

        public static string TradeFileFolderVirtualPath
        {
            get { return TradeFileFolder + "/"; }
        }



        public static string TradeDrawingFolder
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/pagePaths"), NameValueCollection)
            //Return AppPath + nvc("basePage")
            get { return ConfigurationManager.AppSettings["tradeDrawingFolder"].ToString(); }
        }

        public static string TradeDrawingFolderServerPath
        {
            get { return HttpContext.Current.Server.MapPath(TradeDrawingFolder) + "\\"; }
        }

        public static string TradeDrawingFolderVirtualPath
        {
            get { return TradeDrawingFolder + "/"; }
        }

        public static string TradeImageFolder
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/pagePaths"), NameValueCollection)
            //Return AppPath + nvc("basePage")
            get { return ConfigurationManager.AppSettings["tradeImageFolder"].ToString(); }
        }

        public static string TradeImageFolderServerPath
        {
            get { return HttpContext.Current.Server.MapPath(TradeImageFolder) + "\\"; }
        }

        public static string TradeImageFolderVirtualPath
        {
            get { return TradeImageFolder + "/"; }
        }


        /// <summary>
        /// 用户存储检索条件的最大数目
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public static int MaxSavedFilterQuantity
        {

            get
            {
                try
                {
                    return Convert.ToInt16(ConfigurationManager.AppSettings["maxSavedFilterQuantity"].ToString());
                }
                catch (Exception ex)
                {
                    return 10;
                }

            }
        }

        public static int ImageThumbSize
        {
            //Dim nvc As NameValueCollection = CType(ConfigurationManager.GetSection("mouldnet/pagePaths"), NameValueCollection)
            //Return AppPath + nvc("basePage")
            get
            {
                try
                {
                    return int.Parse(ConfigurationManager.AppSettings["imageThumbSize"]);
                }
                catch (Exception ex)
                {
                    return 100;
                }
            }
        }

        //Web構成ファイルのmailSettingsの設定を取得
        public static SmtpSection MailSettings
        {
            get
            {
                try
                {
                    return (SmtpSection)WebConfigurationManager.GetWebApplicationSection("system.net/mailSettings/smtp");

                }
                catch (Exception ex)
                {
                    return null;
                }
            }
        }

        /// <summary>
        /// 产品空间配额的最大数目
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public static int MaxCompanyProductsQuantity
        {

            get
            {
                try
                {
                    return Convert.ToInt16(ConfigurationManager.AppSettings["maxCompanyProductsQuantity"].ToString());
                }
                catch (Exception ex)
                {
                    return 10;
                }

            }
        }

        /// <summary>
        /// 产品认证数的最大数目
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public static int MaxCompanyCertsQuantity
        {

            get
            {
                try
                {
                    return Convert.ToInt16(ConfigurationManager.AppSettings["maxCompanyCertsQuantity"].ToString());
                }
                catch (Exception ex)
                {
                    return 10;
                }

            }
        }

        /// <summary>
        /// 创建供应商库(文件夹)的最大数目
        public static int MaxVendorFolderQuantity
        {

            get
            {
                try
                {
                    return Convert.ToInt16(ConfigurationManager.AppSettings["maxVendorFolderQuantity"].ToString());
                }
                catch (Exception ex)
                {
                    return 5;
                }

            }
        }


        /// <summary>
        /// SPX资源交互的企业信息取得用的URL
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string SpxGetVendInfoUrl
        {

            get
            {
                try
                {
                    return ConfigurationManager.AppSettings["spxGetVendInfoUrl"].ToString();
                }
                catch (Exception ex)
                {
                    return "";
                }

            }
        }

        /// <summary>
        /// SPX资源交互的企业信息取得用的APPID
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string SpxAppid
        {

            get
            {
                try
                {
                    return ConfigurationManager.AppSettings["spxAppid"].ToString();
                }
                catch (Exception ex)
                {
                    return "";
                }

            }
        }

        /// <summary>
        /// SPX资源交互的企业信息取得用的CheckKey
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string SpxCheckKey
        {

            get
            {
                try
                {
                    return ConfigurationManager.AppSettings["spxCheckKey"].ToString();
                }
                catch (Exception ex)
                {
                    return "";
                }

            }
        }
    }
}


